global !p

from mdtex.scopes import math
from builtin import choose_next

matches = {
    "("  : ")",
    "["  : "]",
    "\\{": "\\}",
}

bigs = ["big", "Big", "bigg", "Bigg"]

endglobal

################################################################
#                                                              #
#                          Delimiters                          #
#                                                              #
################################################################

context "math()"
snippet LR "左右 Left Right" Aw
\left$1 $2 \right`!p
try:
    snip.rv = matches[t[1]]
except:
    pass
` $0
endsnippet

context "math()"
snippet "\\\)" "括号 Parenthesis" Air
\left( $1 \right) $0
endsnippet

context "math()"
snippet "\\bb" "LaTeX 专用括号 Parenthesis for LaTeX" Air
\left( $1 \right) $0
endsnippet

context "math()"
snippet "\\\]" "中括号 Bracket" Air
\left[ $1 \right] $0
endsnippet

context "math()"
snippet "\\\}" "大括号 Curly Braces" Air
\left\lbrace $1 \right\rbrace$0
endsnippet

context "math()"
snippet "\\\|" "竖括号 Verticals" ir
\left\lvert $1 \right\rvert$0
endsnippet

context "math()"
snippet "\\>" "尖括号 Angle Brackets" Air
\left\langle $1 \right\rangle$0
endsnippet

context "math()"
snippet "<([^>])+?>" "Description" r
\left\lang `!p snip.rv = match.group(1)` \right\rang
endsnippet

context "math()"
snippet "\\(big|Big|bigg|Bigg)" "Big" r
\\`!p snip.rv = choose_next(match.group(1), bigs, 4)`
endsnippet

priority 1
context "math()"
snippet || "范数 Norm" i
\left\lVert $1 \right\rVert$0
endsnippet
